﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Routing;
using System.Web.Mvc;

namespace BasicCMS
{
    /// <summary>
    /// 路由帮助类
    /// </summary>
    public static class RouteHelper
    {
        /// <summary>
        /// 映射指定的 URL 路由并设置默认的路由值、约束和命名空间,模块名。
        /// </summary>
        /// <param name="routes"></param>
        /// <param name="name"></param>
        /// <param name="url"></param>
        /// <param name="defaults"></param>
        /// <param name="constraints"></param>
        /// <param name="namespaces"></param>
        /// <param name="moduleName"></param>
        /// <returns></returns>
        public static Route MapRoute(this RouteCollection routes, string name, string url, object defaults, object constraints, string[] namespaces, string moduleName)
        {
            Route route = routes.MapRoute(name, url, defaults, constraints, namespaces);

            if (!Util.IsNullOrEmpty(moduleName))
            {
                route.DataTokens["area"] = moduleName;
            }
            return route;
        }
    }
}
